<% content_for :page_title do %>
  <%= link_to Spree.t(:stock_transfers), spree.admin_stock_transfers_url %> /
  <%= Spree.t(:new_stock_transfer) %>
<% end %>

<script type='text/template' id='transfer_variant_template'>
  {{#each variants}}
    <tr>
      <td>{{name}}</td>
      <td class='text-center'>{{quantity}}</td>
      <td class='actions actions-1 text-center'>
        <button class='icon_link btn btn-danger btn-sm transfer_remove_variant' data-variant-id='{{id}}'>
          <span class='icon icon-delete' data-variant-id='{{id}}'></span>
        </button>
        <input type='hidden' id='variant[]' name='variant[]' value='{{id}}'>
        <input type='hidden' id='quantity[]' name='quantity[]' value='{{quantity}}'>
      </td>
    </tr>
  {{/each}}
</script>

<%= form_tag admin_stock_transfers_path, method: :post do %>
  <div class="card mb-3">
    <div class="card-header">
      <h1 class="card-title mb-0 h5">
        <%= Spree.t(:transfer_stock) %>
      </h1>
    </div>

    <div class="card-body">
      <div data-hook="admin_stock_movements_form_fields">
        <div class="form-group" id="stock_movement_reference_field">
          <%= label_tag 'reference', raw("#{Spree.t(:reference)} (#{Spree.t(:optional)})") %>
          <%= text_field_tag :reference, '', class: 'form-control' %>
        </div>
        <div class="form-group" id="receive_stock_field">
          <div class="checkbox">
            <label for="receive_stock">
              <%= check_box_tag :transfer_receive_stock %>
              <%= Spree.t('receive_stock') %>
            </label>
          </div>
        </div>
        <div class="form-group" id="transfer_source_location_id_field">
          <%= label_tag :transfer_source_location_id, Spree.t(:source) %>
          <%= select_tag :transfer_source_location_id, {}, class: 'select2' %>
        </div>
        <div class="form-group" id="transfer_destination_location_id_field">
          <%= label_tag :transfer_destination_location_id, Spree.t(:destination) %>
          <%= select_tag :transfer_destination_location_id, {}, class: 'select2' %>
        </div>
      </div>
    </div>
  </div>

  <div class="card mb-3" id="add-variant-to-transfer">
    <div class="card-header">
      <h1 class="card-title mb-0 h5">
        <%= Spree.t(:add_variant) %>
      </h1>
    </div>

    <div class="card-body">
      <div class="row">
        <div class="col-12 col-lg-8">
          <div class="form-group" id="stock_movement_variant_id_field">
            <%= label_tag 'variant_id', Spree.t(:variant) %>
            <div class="input-group">
              <%= select_tag 'transfer_variant', nil, class: 'd-block w-100', id: 'transfer_variant' %>
            </div>
          </div>
        </div>

        <div class="col-12 col-lg-4">
          <div class="form-group" id="stock_movement_quantity_field">
            <%= label_tag :transfer_variant_quantity, Spree.t(:quantity) %>
            <div class="input-group">
              <%= number_field_tag :transfer_variant_quantity, 1, class: 'form-control', min: 1 %>
              <span class="input-group-btn">
                <%= button Spree.t(:add), 'add.svg', 'submit', class: "transfer_add_variant" %>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="alert alert-info no-objects-found">
    <%= Spree.t(:no_resource_found, resource: I18n.t(:other, scope: 'activerecord.models.spree/variant')) %>.
  </div>

  <div id="transfer-variants-table" style="display:none" class="table-responsive">
    <table class="table table-bordered sortable">
      <thead data-hook="transfer_variants_header">
        <th><%= Spree.t(:name) %></th>
        <th class="text-center"><%= Spree.t(:quantity) %></th>
        <th class="actions"></th>
      </thead>
      <tbody id="transfer_variants_tbody">

      </tbody>
    </table>
  </div>

  <div class="form-actions" data-hook="buttons">
    <%= button Spree.t(:transfer_stock), 'add.svg', class: 'transfer_transfer' %>
  </div>
<% end %>
